package com.jk.vehicle.core.annotation;

import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;
import org.hibernate.validator.constraints.Length;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.Null;
import javax.validation.constraints.Pattern;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 号码校验注解类
 * @author ZhengFangjian
 * @date 2018/10/23
 */
@ConstraintComposition(CompositionType.OR)
@Pattern(regexp = "1[3|4|5|6|7|8|9][0-9]\\d{8}")
@Pattern(regexp = "0\\d{2}-\\d{8}")
@Pattern(regexp = "0\\d{3}-\\d{7}")
@Pattern(regexp = "0\\d{3}-\\d{8}")
@Null
@Length(min = 0, max = 0)
@Documented
@Constraint(validatedBy = {})
@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@ReportAsSingleViolation
public @interface PhoneCheck {

    String message() default "号码格式不正确，若为座机请在区号后加-";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
